using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QLKS
{
    public partial class frmNVSuaKH : Form
    {
        private DataTable _dsKH;

        internal DataTable DsKH
        {
            get { return _dsKH; }
            set { _dsKH = value; }
        }
        public frmNVSuaKH()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmNVSuaKH_Load(object sender, EventArgs e)
        {
            try
            {
                DsKH = BUS.XuLyKhachHang.TimDSKhachHang();

                dgvSuaKH.DataSource = DsKH;

                DataRow dr = DsKH.Rows[0];

                txtTuoi.Text = dr["Tuoi"].ToString();
                txtMaKH.Text = dr["MaKH"].ToString();
                txtTenKH.Text = dr["HoTen"].ToString();
                txtdiachi.Text = dr["DiaChi"].ToString();
                txtCMND.Text = dr["CMND"].ToString();
            }
            catch (System.Exception )
            {
            	
            }
            
        }

        private void btnSuaTT_Click(object sender, EventArgs e)
        {
            if (dgvSuaKH.SelectedRows.Count > 0)
            {
                DTO.CKHACHHANG kh = new DTO.CKHACHHANG();
                int MaKH = int.Parse(txtMaKH.Text);
                kh.MaKH = int.Parse(txtMaKH.Text);
                kh.HoTen = txtTenKH.Text;
                kh.DiaChi = txtdiachi.Text;
                kh.CMND = txtCMND.Text;
                kh.Tuoi = int.Parse(txtTuoi.Text);

                BUS.XuLyKhachHang.SuaTTKhachHang(kh, MaKH);

                frmNVSuaKH_Load(sender, e);
            }
            else
            {
                MessageBox.Show("Ban chua chon khach hang nao ca");
            }
        }

        private void dgvSuaKH_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int index = dgvSuaKH.SelectedRows[0].Index;
            DataRow dr = DsKH.Rows[index];

            txtMaKH.Text = dr["MaKH"].ToString();
            txtTenKH.Text = dr["HoTen"].ToString();
            txtdiachi.Text = dr["DiaChi"].ToString();
            txtCMND.Text = dr["CMND"].ToString();
            txtTuoi.Text = dr["Tuoi"].ToString();
        }
    }
}